#pragma once
#include <iostream>
#include <unordered_map>
#include <mutex>
#include "Common.hpp"
#include "ObjectPool.hpp"

class PackageCache{
public:
    static PackageCache* create()
    {
        return &_Pack;
    }
    //从pc中申请对应span
    Span* NewSpan(size_t k);
    Span* MaptoSpan(void* start);
    void  ReleasePackageSpan(Span* span);

public:
    std::mutex _mutex;
    ObjectPool<Span> _objspan;
private:
    PackageCache(){};
    PackageCache(const PackageCache& other) = delete;
    PackageCache& operator=(const PackageCache& other)=delete;
    static PackageCache _Pack;
    SpanList _splist[Package_Num];
    //哈希映射，可以快速的通过对应的页号找到对应的Span块
    std::unordered_map<PageID,Span*> _idHashMap;
};